const BASE_URL='http://39.108.189.144:4321'
const LOGIN_BASE_URL = "http://123.207.32.32:3000"
 class XXRequest{
   constructor(baseurl){
    this.baseurl = baseurl
   }
  //封装 网络发送请求
   request (url,method,params){
    return new Promise((resolve,reject)=>{
      wx.request({
        url: this.baseurl + url,
        method:method,
        data:params,
        withCredentials: true,
        header:{
          // cookie: wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !==-1):''
          // cookie:wx.getStorageSync('cookies')
        },
        // 成功执行的代码 
        success: function(res){
          // if (url === "/login/cellphone") {
          //   wx.setStorage({
          //     key: "cookies",
          //     data: res.cookies,
          //   });
          // }  
          resolve(res)
        },
        // 失败执行的代码
        fail:function(err){
          reject(err)
        }
      })
    })
  
  }
  // 封装GET请求
  get(url,params,header){
    return this.request(url,"GET",params)
  }
  // 封装POST请求
  post(url,params,header){
    return this.request(url,"POST",params)
  }
}
//创建实例对象 并暴露出去
const xxRequest = new XXRequest(BASE_URL)
const xxLoginRequest =  new XXRequest(LOGIN_BASE_URL)
export default xxRequest
export {
  xxLoginRequest
}